package com.cash.lemoloan.statisticlib.model;

import android.app.ActivityManager;
import android.content.Context;
import android.os.Build;
import android.provider.Settings;

import androidx.annotation.RequiresApi;

import com.cash.lemoloan.statisticlib.StatisticApplication;

import java.util.Objects;

import com.cash.lemoloan.statisticlib.Utils.DevicesUtil;
import com.cash.lemoloan.statisticlib.Utils.PreferencesUtil;


public class StatisticDEV01Info {
     private String statisticctime;
     private String statisticimei;
     private String statisticimsi;//imsi
     private String statisticwifimac;//wifimac
     private String statisticmodel;//设备型号
     private String statisticsysVersion;//系统版本
     private String statisticbrand;
     private String statisticproduct;//产品名
     private String statisticmanufacturer;//制造商
     private String statisticdevice; //设备名
     private String statistichardware; //硬件名
     private String statisticbuild_incremental;//源码控制版本号
     private String statisticboard;//主板
     private String statisticbootloader;
     private String statisticbuild_time; //编译时间
     private String statisticradio_version; //无线电固件版本
     private String statisticbluethoothName;//蓝牙名称
     private String statisticnetworkType; //网络类型
     private String statisticiccid;//获取SIM卡的iccid
     private boolean isRoot;// 手机是否root
     private boolean isWifiProxy; //手机是否使用wifi代理
     private boolean isVpnUsed;
     private String statisticheight;
     private String statisticwidth; //手机屏幕宽度
     private boolean isSimulator;//手机是否使用模拟器
    private Long memTotal;
    private Long memAvail;
    private String statisticbootTime;
    private String statisticandroidId;
    private String statisticadid;
    private String statisticgaid;
    private String statisticphoneNum;
    private String statisticphoneNumber2;
    private boolean statisticnumberP;
    private boolean statisticphoneP;


    public StatisticDEV01Info(){
        setCtime(String.valueOf(System.currentTimeMillis()));
        setImei(DevicesUtil.getIMei());
        setImsi(DevicesUtil.getIMsi());
        setWifimac(DevicesUtil.getMacAddress());
        setModel(DevicesUtil.getDeviceModel());
        setSysVersion(DevicesUtil.getDeviceOsVersion());
        setBrand(DevicesUtil.getBrand());
        setProduct(DevicesUtil.getProduct());
        setManufacturer(DevicesUtil.getManufacturer());
        setDevice(DevicesUtil.getDevice());
        setHardware(DevicesUtil.getHardware());
        setBuild_incremental(DevicesUtil.getBuildIncremental());
        setBoard(DevicesUtil.getBoard());
        setBootloader(DevicesUtil.getBootloader());
        setBuild_time(String.valueOf(DevicesUtil.getBuildTime()));
        setRadio_version(DevicesUtil.getRadioVersion());
        setBluethoothName(DevicesUtil.getBluetoothName());
        setNetworkType(DevicesUtil.getCurrentNetworkType());
        String simiccid = DevicesUtil.getSIMICCID(StatisticApplication.getInstance());
        setIccid(simiccid == null?"":simiccid);
        setRoot(DevicesUtil.isDeviceRooted());
        setWifiProxy(DevicesUtil.isWifiProxy(StatisticApplication.getInstance()));
        setVpnUsed(DevicesUtil.isVpnUsed());
        setSimulator(false);
        setWidth(String.valueOf(DevicesUtil.getWindowWidth(StatisticApplication.getInstance())));
        setHeight(String.valueOf(DevicesUtil.getWindowHeight(StatisticApplication.getInstance())));
        MemoryInfo memoryInfo = getMemoryInfo();
        setMemTotal(memoryInfo.getMemTotal());
        setMemAvail(memoryInfo.getMemAvail());
        setBootTime(String.valueOf(DevicesUtil.getStartTime()));
        setAndroidId(getUuid());
        setAdid(PreferencesUtil.getString("adid"));
        setGaid(PreferencesUtil.getString("googleAdId"));
    }

    public String getAndroidId() {
        return statisticandroidId;
    }

    public void setAndroidId(String id) {
        this.statisticandroidId = id;
    }

    public String getAdid() {
        return statisticadid;
    }

    public void setAdid(String id) {
        this.statisticadid = id;
    }

    public String getGaid() {
        return statisticgaid;
    }

    public void setGaid(String id) {
        this.statisticgaid = id;
    }

    public static String getUuid() {
        try {
            return Settings.Secure.getString(StatisticApplication.getInstance().getContentResolver(),
                    Settings.Secure.ANDROID_ID);
        } catch (Throwable e) {
            return "android_id_unknown";
        }
    }

    public void setStatisticphoneNum(String statisticphoneNum) {
        this.statisticphoneNum = statisticphoneNum;
    }

    public void setStatisticphoneNumber2(String statisticphoneNumber2) {
        this.statisticphoneNumber2 = statisticphoneNumber2;
    }

    public void setStatisticnumberP(boolean statisticnumberP) {
        this.statisticnumberP = statisticnumberP;
    }

    public void setStatisticphoneP(boolean statisticphoneP) {
        this.statisticphoneP = statisticphoneP;
    }

    @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
    public static MemoryInfo getMemoryInfo(){
        ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
        try {
            ActivityManager activityManager = (ActivityManager) StatisticApplication.getInstance().getSystemService(Context.ACTIVITY_SERVICE);
            activityManager.getMemoryInfo(memoryInfo);
        }catch (Exception e){
        }finally {
            return new MemoryInfo(memoryInfo.totalMem,memoryInfo.availMem);
        }

    }



    public String getCtime() {
        return statisticctime;
    }

    public void setCtime(String ctime) {
        this.statisticctime = ctime;
    }

    public String getImei() {
        return statisticimei;
    }

    public void setImei(String imei) {
        this.statisticimei = imei;
    }

    public String getImsi() {
        return statisticimsi;
    }

    public void setImsi(String imsi) {
        this.statisticimsi = imsi;
    }

    public String getWifimac() {
        return statisticwifimac;
    }

    public void setWifimac(String wifimac) {
        this.statisticwifimac = wifimac;
    }

    public String getModel() {
        return statisticmodel;
    }

    public void setModel(String model) {
        this.statisticmodel = model;
    }

    public String getSysVersion() {
        return statisticsysVersion;
    }

    public void setSysVersion(String sysVersion) {
        this.statisticsysVersion = sysVersion;
    }

    public String getBrand() {
        return statisticbrand;
    }

    public void setBrand(String brand) {
        this.statisticbrand = brand;
    }

    public String getProduct() {
        return statisticproduct;
    }

    public void setProduct(String product) {
        this.statisticproduct = product;
    }

    public String getManufacturer() {
        return statisticmanufacturer;
    }

    public void setManufacturer(String manufacturer) {
        this.statisticmanufacturer = manufacturer;
    }

    public String getDevice() {
        return statisticdevice;
    }

    public void setDevice(String device) {
        this.statisticdevice = device;
    }

    public String getHardware() {
        return statistichardware;
    }

    public void setHardware(String hardware) {
        this.statistichardware = hardware;
    }

    public String getBuild_incremental() {
        return statisticbuild_incremental;
    }

    public void setBuild_incremental(String build_incremental) {
        this.statisticbuild_incremental = build_incremental;
    }

    public String getBoard() {
        return statisticboard;
    }

    public void setBoard(String board) {
        this.statisticboard = board;
    }

    public String getBootloader() {
        return statisticbootloader;
    }

    public void setBootloader(String bootloader) {
        this.statisticbootloader = bootloader;
    }

    public String getBuild_time() {
        return statisticbuild_time;
    }

    public void setBuild_time(String build_time) {
        this.statisticbuild_time = build_time;
    }

    public String getRadio_version() {
        return statisticradio_version;
    }

    public void setRadio_version(String radio_version) {
        this.statisticradio_version = radio_version;
    }

    public String getBluethoothName() {
        return statisticbluethoothName;
    }

    public void setBluethoothName(String bluethoothName) {
        this.statisticbluethoothName = bluethoothName;
    }

    public String getNetworkType() {
        return statisticnetworkType;
    }

    public void setNetworkType(String networkType) {
        this.statisticnetworkType = networkType;
    }

    public String getIccid() {
        return statisticiccid;
    }

    public void setIccid(String iccid) {
        this.statisticiccid = iccid;
    }

    public boolean isRoot() {
        return isRoot;
    }

    public void setRoot(boolean root) {
        isRoot = root;
    }

    public boolean isWifiProxy() {
        return isWifiProxy;
    }

    public void setWifiProxy(boolean wifiProxy) {
        isWifiProxy = wifiProxy;
    }

    public boolean isVpnUsed() {
        return isVpnUsed;
    }

    public void setVpnUsed(boolean vpnUsed) {
        isVpnUsed = vpnUsed;
    }

    public String getHeight() {
        return statisticheight;
    }

    public void setHeight(String height) {
        this.statisticheight = height;
    }

    public String getWidth() {
        return statisticwidth;
    }

    public void setWidth(String width) {
        this.statisticwidth = width;
    }

    public boolean isSimulator() {
        return isSimulator;
    }

    public void setSimulator(boolean simulator) {
        isSimulator = simulator;
    }

    public Long getMemTotal() {
        return memTotal;
    }

    public void setMemTotal(Long memTotal) {
        this.memTotal = memTotal;
    }

    public Long getMemAvail() {
        return memAvail;
    }

    public void setMemAvail(Long memAvail) {
        this.memAvail = memAvail;
    }

    public String getBootTime() {
        return statisticbootTime;
    }

    public void setBootTime(String bootTime) {
        this.statisticbootTime = bootTime;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        StatisticDEV01Info dev01Info = (StatisticDEV01Info) o;
        return isRoot == dev01Info.isRoot && isWifiProxy == dev01Info.isWifiProxy && isVpnUsed == dev01Info.isVpnUsed && isSimulator == dev01Info.isSimulator && Objects.equals(statisticctime, dev01Info.statisticctime) && Objects.equals(statisticimei, dev01Info.statisticimei) && Objects.equals(statisticimsi, dev01Info.statisticimsi) && Objects.equals(statisticwifimac, dev01Info.statisticwifimac) && Objects.equals(statisticmodel, dev01Info.statisticmodel) && Objects.equals(statisticsysVersion, dev01Info.statisticsysVersion) && Objects.equals(statisticbrand, dev01Info.statisticbrand) && Objects.equals(statisticproduct, dev01Info.statisticproduct) && Objects.equals(statisticmanufacturer, dev01Info.statisticmanufacturer) && Objects.equals(statisticdevice, dev01Info.statisticdevice) && Objects.equals(statistichardware, dev01Info.statistichardware) && Objects.equals(statisticbuild_incremental, dev01Info.statisticbuild_incremental) && Objects.equals(statisticboard, dev01Info.statisticboard) && Objects.equals(statisticbootloader, dev01Info.statisticbootloader) && Objects.equals(statisticbuild_time, dev01Info.statisticbuild_time) && Objects.equals(statisticradio_version, dev01Info.statisticradio_version) && Objects.equals(statisticbluethoothName, dev01Info.statisticbluethoothName) && Objects.equals(statisticnetworkType, dev01Info.statisticnetworkType) && Objects.equals(statisticiccid, dev01Info.statisticiccid) && Objects.equals(statisticheight, dev01Info.statisticheight) && Objects.equals(statisticwidth, dev01Info.statisticwidth) && Objects.equals(memTotal, dev01Info.memTotal) && Objects.equals(memAvail, dev01Info.memAvail) && Objects.equals(statisticbootTime, dev01Info.statisticbootTime);
    }

    @Override
    public int hashCode() {
        return Objects.hash(statisticctime, statisticimei, statisticimsi, statisticwifimac, statisticmodel, statisticsysVersion, statisticbrand, statisticproduct, statisticmanufacturer, statisticdevice, statistichardware, statisticbuild_incremental, statisticboard, statisticbootloader, statisticbuild_time, statisticradio_version, statisticbluethoothName, statisticnetworkType, statisticiccid, isRoot, isWifiProxy, isVpnUsed, statisticheight, statisticwidth, isSimulator, memTotal, memAvail, statisticbootTime);
    }

    @Override
    public String toString() {
        return "DEV01Info{" +
                "statisticctime='" + statisticctime + '\'' +
                ", statisticimei='" + statisticimei + '\'' +
                ", statisticimsi='" + statisticimsi + '\'' +
                ", statisticwifimac='" + statisticwifimac + '\'' +
                ", statisticmodel='" + statisticmodel + '\'' +
                ", statisticsysVersion='" + statisticsysVersion + '\'' +
                ", statisticbrand='" + statisticbrand + '\'' +
                ", statisticproduct='" + statisticproduct + '\'' +
                ", statisticmanufacturer='" + statisticmanufacturer + '\'' +
                ", statisticdevice='" + statisticdevice + '\'' +
                ", statistichardware='" + statistichardware + '\'' +
                ", statisticbuild_incremental='" + statisticbuild_incremental + '\'' +
                ", statisticboard='" + statisticboard + '\'' +
                ", statisticbootloader='" + statisticbootloader + '\'' +
                ", statisticbuild_time='" + statisticbuild_time + '\'' +
                ", statisticradio_version='" + statisticradio_version + '\'' +
                ", statisticbluethoothName='" + statisticbluethoothName + '\'' +
                ", statisticnetworkType='" + statisticnetworkType + '\'' +
                ", statisticiccid='" + statisticiccid + '\'' +
                ", isRoot=" + isRoot +
                ", isWifiProxy=" + isWifiProxy +
                ", isVpnUsed=" + isVpnUsed +
                ", statisticheight='" + statisticheight + '\'' +
                ", statisticwidth='" + statisticwidth + '\'' +
                ", isSimulator=" + isSimulator +
                ", memTotal=" + memTotal +
                ", memAvail=" + memAvail +
                ", statisticbootTime='" + statisticbootTime + '\'' +
                '}';
    }
}
